Requires the CodeAChrome.DLL to run. You can find all files in the zipped archive of this issue.
'** Eddie - an LB Code Editor
'version 12
'added ability to change font size
'changed ini file to API version
'check to see if window is minimized at close
'if window is not minimized, save coords to use at next run
'******************************************************
'CodeAChrome is copyright Alyce Watson, 2005.
'******************************************************
'CodeAChrome is free for commercial and non-commercial use.
'A credit to the author and a link to the website must be
'included in your program's documentation or readme file,
'and in any source code released to the public.
'Alyce Watson
'http://alycesrestaurant.com/
'******************************************************
'Use this DLL at your own risk. The author bears no responsibility
'for errors that may occur as the result of its use.
'******************************************************
'You may not reverse-engineer this DLL.
'You may not claim it as your own work.
'******************************************************
if val(Version$)<4.02 then
notice "For Liberty BASIC v4.02 and higher."
end
end if
[VariableSetup]
'#f will be the handle for opening files
'note that Version$ is a reserved variable name
EddieVersion$ = "12"
LibertyExe$ = "" 'path to Liberty.exe for running programs:
Freeform$ = "" 'path to Freeform
Runtime$ = "" 'path to runtime engine, run402.exe
Help$ = "" 'path to LB help
IniFile$ = "eddie10.ini" 'name of ini file for this version of Eddie
Curdir$ = DefaultDir$
text$ = "" 'variable to hold contents of texteditor
TextColor$ = "0 0 0" 'default text color = black
BackColor$ = "255 255 255" 'default background color = white
KeywordColor$ = "0 0 255" 'default keyword color = blue
QuoteColor$ = "123 0 123" 'default quote color = darkpink
CommentColor$ = "0 123 0" 'default comment color = darkgreen
OperatorColor$ = "255 0 0" 'default operator color = red
FontSize$ = "10" 'default font height
tempfile$ = DefaultDir$ + "\tempfile.bas" 'filename for writing a temp file to disk
savefile$ = "" 'filename for user saving file to disk
dim branch$(1000) 'array to hold branch labels
branch$(1) = "" 'first designation takes you to top of code
gosub [readIniFile]
[WindowSetup]
NOMAINWIN
[ControlSetup]
Menu #1, "&File", "&New", [new], "&Open", [open], "Open as &RTF", [openRTF],_
"&Save", [save], "Save as R&TF", [saveRTF],_
|,"&Print", [print], "E&xit", [quit]
Menu #1, "&Edit", "&Undo",[undo],"Cu&t",[cut],"&Copy",[copy],"&Paste",[paste],|,_
"&Select All",[selectall]
Menu #1, "&Options", "&Syntax Color On/Off",[syntaxColor],"&Line Numbers On/Off",[lineNumbers],|,_
"Set &Default Color", [doDefaultColor],"Set &Background Color", [doBackgroundColor],|,_
"Set &Keyword Color", [doKeywordColor],"Set &Comment Color", [doCommentColor],"Set &Quote Color",_
[doQuoteColor],"Set &Operator Color", [doOperatorColor], |, "&Font Size", [changeFont]
Menu #1, "&Run","R&un", [run]
Menu #1, "&Tools", "&Go to Line", [gotoLine], "&Freeform", [freeform]
Menu #1, "&Help", "He&lp", [help], "&About", [about]
'buttons for a toolbar lookalike
button #1.new, "New",[new],UL, 0, 0, 45, 20
button #1.open, "Open",[open],UL, 45, 0, 45, 20
button #1.save, "Save",[save],UL, 90, 0, 45, 20
button #1.print, "Print",[print],UL, 135, 0, 45, 20
button #1.cut, "Cut",[cut],UL, 190, 0, 45, 20
button #1.copy, "Copy",[copy],UL, 235, 0, 45, 20
button #1.paste, "Paste",[paste],UL, 280, 0, 45, 20
button #1.run, "Run",[run],UL, 335, 0, 45, 20
button #1.help, "Help",[help],UL, 380, 0, 45, 20
stylebits #1.c, 0,_CBS_AUTOHSCROLL,0,0
combobox #1.c, branch$(),[chooseBranch],40,22,385,300
Open "Eddie - an LB Code Editor v." + EddieVersion$ for Window as #1
'trap the close event, if the user closes the
'window with the X button
#1 "trapclose [quit]"
#1 "resizehandler [resize]"
'set the font for the window and controls
#1 "font ms_sans_serif 10"
'select item in combobox
#1.c "selectindex 1"
open "CodeAChrome.dll" for dll as #r
hMain = hwnd(#1) 'handle of program window
calldll #r, "CreateCodeAChrome",_ 'code editing component
hMain as long,_ 'handle of program window
0 as long,_ 'x location of control
52 as long,_ 'y location of control
545 as long,_ 'width of control
250 as long,_ 'height of control
ret as long 'nonzero=success
if ret=0 then
notice "Error loading CodeAChrome. Program ended."
goto [quit]
end if
'activate resizehandler
calldll #user32, "MoveWindow",_
hMain as ulong, _ 'window handle
ULX as long,_ 'x location of window
ULY as long,_ 'y location of window
WIDTH as long,_ 'desired width of window
HEIGHT as long,_ 'desired height of window
1 as boolean, ret as long
calldll #r, "SetContextMenuOn",_ 'right-click menu
0 as long,_ '1 = on, 0 = off
ret as void 'no return
calldll #r, "DoSetFocus",_ 'setfocus to codeachrome
ret as void 'no return
keys$ = " abs acs append as asc asn atn backgroundcolor$ beep binary bmpbutton bmpsave boolean button call "
keys$ = keys$ + " callback calldll case checkbox chr$ close cls colordialog combobox comboboxcolor$ commandline$ "
keys$ = keys$ + " confirm cos cursor data date$ dechex$ defaultdir$ dialog dialog_fs dialog_modal dialog_nf dialog_nf_modal "
keys$ = keys$ + " dialog_nf_fs dim displayheight displaywidth dll do drives$ dword dump else end eof err error err$ eval "
keys$ = keys$ + " eval$ exit exp field filedialog files fontdialog end for foregroundcolor$ function get gettrim global "
keys$ = keys$ + " gosub goto graphics graphics_fs graphics_fs_nsb graphics_nsb graphics_nf_nsb graphicbox groupbox hbmp "
keys$ = keys$ + " hexdec hwnd if inkey$ inp input input$ inputto$ instr int joy1x joy1y joy1z joy1button1 joy1button2 joy2x "
keys$ = keys$ + " joy2y joy2z joy2button1 joy2button2 kill left$ len let line listbox listboxcolor$ ll loadbmp locate loc "
keys$ = keys$ + " lof log long loop lower$ lprint lr maphandle max menu midipos mid$ min mkdir mod name next nomainwin "
keys$ = keys$ + " notice on open out output platform$ playmidi playwave popupmenu print printerdialog printerfont$ prompt "
keys$ = keys$ + " ptr put radiobutton randomize read readjoystick redim rem restore resume return right$ rmdir rnd run "
keys$ = keys$ + " scan seek select short sin sort space$ spreadsheet sqr statictext str$ stopmidi struct stylebits sub "
keys$ = keys$ + " tab tan text textbox textboxcolor$ texteditor texteditorcolor$ text_fs text_nsb text_nsb_ins then time$ "
keys$ = keys$ + " timer titlebar trace trim$ txcount ul ulong unloadbmp until upper$ upperleftx upperlefty ur ushort using "
keys$ = keys$ + " val version$ void wait wend while window windowheight windowwidth window_nf winstring word word$ "
calldll #r, "SetKeyWords",_ 'replace keywords with string
keys$ as ptr,_ 'string containing keywords separated by spaces
ret as void 'no return
call SetTextColor TextColor$
call SetBackgroundColor BackColor$
call SetKeywordColor KeywordColor$
call SetQuoteColor QuoteColor$
call SetCommentColor CommentColor$
call SetOperatorColor OperatorColor$
call SetFontSize FontSize$
wait
[loop] Wait
[quit]
calldll #user32, "IsIconic",_
hMain as ulong,_ 'handle of window
result as boolean 'returns true if window is minimized
if not(result) then
struct Rect, x1 As Long, y1 As Long, x2 As Long, y2 As Long
CallDLL #user32, "GetWindowRect",hMain as uLong, Rect As struct, result As Long
ulx = Rect.x1.struct : uly = Rect.y1.struct
width = Rect.x2.struct - ulx
height = Rect.y2.struct - uly
'write location and size of window to ini file
call WriteIniFile "Eddie", "ULX", str$(ulx), "eddie12.ini"
call WriteIniFile "Eddie", "ULY", str$(uly), "eddie12.ini"
call WriteIniFile "Eddie", "WIDTH", str$(width), "eddie12.ini"
call WriteIniFile "Eddie", "HEIGHT", str$(height), "eddie12.ini"
end if
gosub [writeIniFile]
calldll #r, "DestroyCodeAChrome", ret as void
close #r : close #1 : END
[syntaxColor]
confirm "Use syntax colors?";ans$
if ans$ = "yes" then togglecol = 1 else togglecol = 0
calldll #r, "SetSyntaxColorOn",_ 'use syntax coloring
togglecol as long,_ '1 = on, 0 = off
ret as void 'no return
calldll #r, "DoSetFocus", re as void
wait
[lineNumbers]
confirm "Use line numbers?";ans$
if ans$ = "yes" then togglelines = 1 else togglelines = 0
calldll #r, "SetLineNumbersOn",_ 'use line numbers?
togglelines as long,_ '1 = on, 0 = off
ret as void 'no return
calldll #r, "DoSetFocus", re as void
wait
[new]
calldll #r, "DoNew",_ 'clear control
re as void
Wait
[open]
filedialog "Open",Curdir$ + "\*.bas",openfile$
if openfile$="" then wait
Curdir$ = SeparatePath$(openfile$)
calldll #r, "FileLoad",_ 'load file into codeachrome
openfile$ as ptr,_ 'name of file
re as void 'no return
gosub [fillBranch]
Wait
[save]
filedialog "Save As",Curdir$ + "\*.bas",savefile$
if savefile$="" then wait
'make sure that user had given the file a *bas extension
if right$(lower$(savefile$),4)<>".bas" then
savefile$=savefile$+".bas"
end if
Curdir$ = SeparatePath$(savefile$)
calldll #r, "FileSave",_ 'save contents to disk
savefile$ as ptr,_ 'save filename
re as void
Wait
[openRTF] 'open a rich text file and load into Eddie
filedialog "Open",Curdir$ + "\*.rtf",openfile$
if openfile$="" then wait
Curdir$ = SeparatePath$(openfile$)
calldll #r, "FileLoadAsRTF",_ 'load file into codeachrome
openfile$ as ptr,_ 'name of file
re as void 'no return
gosub [fillBranch]
Wait
[saveRTF] 'save in rich text format
filedialog "Save As",Curdir$ + "\*.rtf",savefile$
if savefile$="" then wait
'make sure that user had given the file a *rtf extension
if right$(lower$(savefile$),4)<>".rtf" then
savefile$=savefile$+".rtf"
end if
Curdir$ = SeparatePath$(savefile$)
calldll #r, "FileSaveAsRTF",_ 'save contents to disk
savefile$ as ptr,_ 'save filename
re as void
Wait
[print]
calldll #r, "DoPrint",_ 'print contents of control
re as void
Wait
[help]
if Help$ = "" then gosub [FindHelpPath]
if Help$ = "" then wait
run "winhlp32 " + chr$(34) + Help$ + chr$(34)
Wait
[about]
notice "CodeAChrome code editing component is copyrighted by Alyce Watson, 2005."
Wait
[undo]
calldll #r, "EditUndo",_ 'undo last operation
re as void
wait
[cut]
calldll #r, "EditCutText",_ 'cut selected text to clipboard
re as void
wait
[copy]
calldll #r, "EditCopyText",_ 'copy selected text to clipboard
re as void
wait
[paste]
calldll #r, "EditPasteText",_ 'paste contents of clipboard at cursor
re as void
wait
[selectall]
calldll #r, "EditSelectAll",_ 'select all text in control
re as void
wait
[run]
if LibertyExe$ = "none" then gosub [GetLibertyPath]
'if we can't find the path to Liberty BASIC
'we must abort the RUN operation
if LibertyExe$="" then wait
calldll #r, "FileSave",_ 'save contents to disk
tempfile$ as ptr,_ 'save filename
re as void
RUN LibertyExe$ + " -R " + tempfile$
wait
[freeform]
if Freeform$ = "none" then gosub [GetFreeformPath]
if Freeform$ = "" then wait
if Runtime$ = "" then gosub [GetRuntimePath]
if Runtime$="" then wait
run Runtime$ + " " + chr$(34) + Freeform$ + chr$(34)
wait
[GetLibertyPath]
filedialog "Find Liberty.exe",Curdir$ + "\*liberty*.exe",LibertyExe$
if LibertyExe$="" then
notice "Liberty.exe not found."
else
Curdir$ = SeparatePath$(LibertyExe$)
end if
RETURN
[GetRuntimePath]
filedialog "Find runtime engine",Curdir$ + "\*run*.exe",Runtime$
if Runtime$="" then
notice "Runtime engine not found."
else
Curdir$ = SeparatePath$(Runtime$)
end if
RETURN
[GetFreeformPath]
filedialog "Find Freeform",Curdir$ + "\*.tkn",Freeform$
if Freeform$="" then
notice "Freeform not found."
else
Curdir$ = SeparatePath$(Freeform$)
end if
RETURN
[GetHelpPath]
filedialog "Find Help",Curdir$ + "\*.hlp",Help$
if Help$="" then
notice "Help not found."
else
Curdir$ = SeparatePath$(Help$)
end if
RETURN
[fillBranch]
calldll #r, "GetNumberOfLines",_
rowcount as long 'returns number of lines, 0-indexed
rowcount = rowcount - 1 'because lines begin at 0
REDIM branch$(rowcount)
branch$(1)="" + space$(300) + "1"
'fill combobox with labels, functions and sub definitions
'pad with 300 spaces, then add line number
bx=2
For i=0 to rowcount
calldll #r, "GetLineTextLength",_ 'retrieve length of text in line
i as long,_ 'index of line
length as long 'returns length
line$ = space$(length + 1) 'create buffer to receive text
calldll #r, "GetLineText",_
i as long,_ 'index of line to retrieve
line$ as ptr,_ 'buffer for text
ret as void
If Left$(Trim$(line$),1)="[" Then
branch$(bx)=Trim$(line$) + space$(300) + str$(i)
bx=bx+1
End If
If Lower$(Word$(line$,1))="function" Then
branch$(bx)=Trim$(line$) + space$(300) + str$(i)
bx=bx+1
End If
If Lower$(Word$(line$,1))="sub" Then
branch$(bx)=Trim$(line$) + space$(300) + str$(i)
bx=bx+1
End If
Next
#1.c "reload"
#1.c "selectindex 1";
return
[chooseBranch]
'** CHOOSE BRANCH, SET EDITOR TO THAT POSITION
#1.c "selection? branchselect$"
'get the text at the end of the item
ln$ = right$(branchselect$, 6)
'get value of text, which will = linenumber
linenumber = val(ln$)
'now scroll texteditor so that line is at top
calldll #r, "SetTopLine",_ 'scroll this line to top
linenumber as long,_ 'index of line
re as void 'no return
Wait
[gotoLine]
calldll #r, "GetNumberOfLines",_
rowcount as long 'returns number of lines, 0-indexed
gotoLine=rowcount-1
msg$="Go to line? Max is ";gotoLine
prompt msg$;gotoLine
if gotoLine>rowcount-1 then gotoLine=rowcount
if gotoLine<0 then gotoLine=0
calldll #r, "SetTopLine",_ 'scroll this line to top
gotoLine as long,_ 'index of line
re as void 'no return
wait
Function SeparatePath$(f$)
fileindex=Len(f$)
filelength=Len(f$)
While Mid$(f$, fileindex,1)<>"\"
fileindex=fileindex-1
Wend
SeparatePath$=Left$(f$,fileindex)
End Function
[resize]
ww=WindowWidth : wh=WindowHeight-52
calldll #r, "MoveCodeAChrome",_ 'move/resize the control
0 as long,_ 'new x location
52 as long,_ 'new y location
ww as long,_ 'new width
wh as long,_ 'new height
re as void
#1 "refresh"
wait
[doDefaultColor]
colordialog TextColor$, TextColor$
call SetTextColor TextColor$
wait
Sub SetTextColor Color$
red = val(word$(Color$,1))
green = val(word$(Color$,2))
blue = val(word$(Color$,3))
calldll #r, "SetDefaultColor",_ 'set default text color
red as long,_ 'red 0-255
green as long,_ 'green 0-255
blue as long,_ 'blue 0-255
re as void
calldll #r, "ColorAll",_ 'recolor text to reflect user choices
re as void
End Sub
[doBackgroundColor]
colordialog BackColor$, BackColor$
call SetBackgroundColor BackColor$
wait
Sub SetBackgroundColor Color$
red = val(word$(Color$,1))
green = val(word$(Color$,2))
blue = val(word$(Color$,3))
calldll #r, "SetBackgroundColor",_ 'set editor background color
red as long,_ 'red 0-255
green as long,_ 'green 0-255
blue as long,_ 'blue 0-255
re as void
calldll #r, "ColorAll",_ 'recolor text to reflect user choices
re as void
End Sub
[doKeywordColor]
colordialog KeywordColor$, KeywordColor$
call SetKeywordColor KeywordColor$
wait
Sub SetKeywordColor Color$
red = val(word$(Color$,1))
green = val(word$(Color$,2))
blue = val(word$(Color$,3))
calldll #r, "SetKeyColor",_ 'set color for keywords
red as long,_ 'red 0-255
green as long,_ 'green 0-255
blue as long,_ 'blue 0-255
re as void
calldll #r, "ColorAll",_ 'recolor text to reflect user choices
re as void
End Sub
[doQuoteColor]
colordialog QuoteColor$, QuoteColor$
call SetQuoteColor QuoteColor$
wait
Sub SetQuoteColor Color$
red = val(word$(Color$,1))
green = val(word$(Color$,2))
blue = val(word$(Color$,3))
calldll #r, "SetQuoteColor",_ 'set color for quoted text
red as long,_ 'red 0-255
green as long,_ 'green 0-255
blue as long,_ 'blue 0-255
re as void
calldll #r, "ColorAll",_ 'recolor text to reflect user choices
re as void
End Sub
[doCommentColor]
colordialog CommentColor$, CommentColor$
call SetCommentColor CommentColor$
wait
Sub SetCommentColor Color$
red = val(word$(Color$,1))
green = val(word$(Color$,2))
blue = val(word$(Color$,3))
calldll #r, "SetCommentColor",_ 'set color for comments
red as long,_ 'red 0-255
green as long,_ 'green 0-255
blue as long,_ 'blue 0-255
re as void
calldll #r, "ColorAll",_ 'recolor text to reflect user choices
re as void
End Sub
[doOperatorColor]
colordialog OperatorColor$, OperatorColor$
call SetOperatorColor OperatorColor$
wait
Sub SetOperatorColor Color$
red = val(word$(Color$,1))
green = val(word$(Color$,2))
blue = val(word$(Color$,3))
calldll #r, "SetOperatorColor",_ 'set color for operators like +=[]
red as long,_ 'red 0-255
green as long,_ 'green 0-255
blue as long,_ 'blue 0-255
re as void
calldll #r, "ColorAll",_ 'recolor text to reflect user choices
re as void
End Sub
[changeFont]
nFont = val(FontSize$)
prompt "Size for font?";nFont
if nFont<8 then nFont = 8
if nFont>24 then nFont = 24
FontSize$ = str$(nFont)
call SetFontSize FontSize$
wait
Sub SetFontSize fSize$
nFont = val(fSize$)
calldll #r, "SetFontSize", nFont as long, re as void
calldll #r, "DoSetFocus", re as void
end sub
[readIniFile]
LibertyExe$ = GetIniFile$("Eddie", "LibertyExe","none","eddie12.ini")
Freeform$ = GetIniFile$("Eddie", "Freeform","none","eddie12.ini")
Runtime$ = GetIniFile$("Eddie", "Runtime","none","eddie12.ini")
Help$ = GetIniFile$("Eddie", "Help","none","eddie12.ini")
TextColor$ = GetIniFile$("Eddie", "TextColor",TextColor$,"eddie12.ini")
BackColor$ = GetIniFile$("Eddie", "BackColor",BackColor$,"eddie12.ini")
KeywordColor$ = GetIniFile$("Eddie", "KeywordColor",KeywordColor$,"eddie12.ini")
QuoteColor$ = GetIniFile$("Eddie", "QuoteColor",QuoteColor$,"eddie12.ini")
CommentColor$ = GetIniFile$("Eddie", "CommentColor",CommentColor$,"eddie12.ini")
OperatorColor$ = GetIniFile$("Eddie", "OperatorColor",OperatorColor$,"eddie12.ini")
FontSize$ = GetIniFile$("Eddie", "FontSize",FontSize$,"eddie12.ini")
'window X,Y,WIDTH,HEIGHT at user's last values
ULX = VAL(GetIniFile$("Eddie", "ULX","10","eddie12.ini"))
ULY = VAL(GetIniFile$("Eddie", "ULY","10","eddie12.ini"))
WIDTH = VAL(GetIniFile$("Eddie", "WIDTH","400","eddie12.ini"))
HEIGHT = VAL(GetIniFile$("Eddie", "HEIGHT","300","eddie12.ini"))
if LibertyExe$ = "none" then
notice "To use Eddie successfully, you must set the path to Liberty.exe, Freeform, the runtime engine and the helpfile."
gosub [GetLibertyPath]
gosub [GetFreeformPath]
gosub [GetRuntimePath]
gosub [GetHelpPath]
end if
RETURN
[writeIniFile]
call WriteIniFile "Eddie", "LibertyExe", LibertyExe$,"eddie12.ini"
call WriteIniFile "Eddie", "Freeform", Freeform$,"eddie12.ini"
call WriteIniFile "Eddie", "Runtime", Runtime$,"eddie12.ini"
call WriteIniFile "Eddie", "Help", Help$,"eddie12.ini"
call WriteIniFile "Eddie", "TextColor", TextColor$,"eddie12.ini"
call WriteIniFile "Eddie", "BackColor", BackColor$,"eddie12.ini"
call WriteIniFile "Eddie", "KeywordColor", KeywordColor$,"eddie12.ini"
call WriteIniFile "Eddie", "QuoteColor", QuoteColor$,"eddie12.ini"
call WriteIniFile "Eddie", "CommentColor", CommentColor$,"eddie12.ini"
call WriteIniFile "Eddie", "OperatorColor", OperatorColor$,"eddie12.ini"
call WriteIniFile "Eddie", "FontSize", FontSize$,"eddie12.ini"
RETURN
Sub WriteIniFile lpAppName$, lpKeyName$, lpString$, lpFileName$
CallDLL #kernel32, "WritePrivateProfileStringA", _
lpAppName$ As ptr, _ 'section name
lpKeyName$ As ptr, _ 'key name
lpString$ As ptr, _ 'key value
lpFileName$ As ptr, _ 'ini filename
result As boolean 'nonzero = success
end sub
Function GetIniFile$(lpAppName$, lpKeyName$,lpDefault$,lpFileName$)
nSize=100
lpReturnedString$=Space$(nSize)+Chr$(0)
CallDLL #kernel32, "GetPrivateProfileStringA", _
lpAppName$ As ptr, _'section name
lpKeyName$ As ptr, _'key name
lpDefault$ As ptr, _'default string returned if there is no entry
lpReturnedString$ As ptr, _ 'destination buffer
nSize As long, _ 'size of destination buffer
lpFileName$ As ptr, _ 'ini filename
result As ulong 'number of characters copied to buffer
GetIniFile$=Left$(lpReturnedString$,result)
end function